package com.yang.aiDoctor.controller;

import com.yang.aiDoctor.bean.ChatEntity;
import com.yang.aiDoctor.service.AIService;
import groovy.util.logging.Slf4j;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;
import java.util.Map;

@lombok.extern.slf4j.Slf4j
@Slf4j
@RestController()
@RequestMapping("/ai")
public class ChatController {


    @Resource
    private AIService aiService;

    @GetMapping("/generate")
    public Map generate(@RequestParam(value = "message", defaultValue = "hello,who are you?") String message) {
        return aiService.aiChat(message);
    }

    @GetMapping("/generateStream")
    public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "hello,who are you?") String message) {
        return aiService.aiChatStream(message);
    }

    @GetMapping("/generateStream2")
    public List<String> generateStream2(@RequestParam(value = "message", defaultValue = "hello,who are you?") String message) {
        return aiService.aiChatStream2(message);
    }
    @PostMapping("/chat")
    public String chatWithDoctor(@RequestBody ChatEntity chatEntity) {
        log.info(chatEntity.toString());
        String currentUserName = chatEntity.getCurrentUserName();
        String message = chatEntity.getMessage();
        return aiService.chatWithDoctor(currentUserName,message);
    }
}
